//
//  YBTopDownButton.m
//  HomeDoorWay
//
//  Created by apple on 17/9/18.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "YBTopDownButton.h"

@implementation YBTopDownButton

- (instancetype)initWithFrame:(CGRect)frame text:(NSString *)text textColor:(UIColor *)textColor imageName:(NSString *)imageName font:(CGFloat)font imageSize:(CGFloat)imageSize theInterval:(CGFloat)theInterval
{
    self = [super initWithFrame:frame];
    if (self) {
        CGSize size = [text boundingRectWithSize:CGSizeMake(frame.size.width, frame.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:font]} context:nil].size;
        CGFloat beginY = (frame.size.height - (size.height + theInterval + imageSize)) / 2;
        self.theImageView = [[UIImageView alloc]initWithFrame:CGRectMake((frame.size.width - imageSize) / 2, beginY, imageSize, imageSize)];
        self.theImageView.image = [UIImage imageNamed:imageName];
        [self addSubview:self.theImageView];
        
        self.theLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, beginY + imageSize + theInterval, frame.size.width, size.height)];
        if (textColor) {
            self.theLabel.textColor = textColor;
        }
        self.theLabel.font = LYPFONT(font);
        self.theLabel.text = text;
        self.theLabel.numberOfLines = 0;
        self.theLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.theLabel];
        
        self.badgeView = [[UIView alloc]initWithFrame:CGRectMake(self.theImageView.right + ItemPX * 5, self.theImageView.top + ItemPX * 5, ItemPX * 20, ItemPX * 20)];
        self.badgeView.layer.cornerRadius = ItemPX * 10;
        self.badgeView.backgroundColor = [UIColor redColor];
        self.badgeView.hidden = YES;
        [self addSubview:self.badgeView];
    }
    return self;
}


@end
